package com.imooc.study.scalaClasses

object BasicClass {
  def main(args: Array[String]): Unit = {
    // 1.基础写法
//    class Person(var firstName : String, var lastName : String)
//    val p = new Person("Bill", "Panner")
//    println(p.firstName + " " + p.lastName)
//    p.firstName = "William"
//    p.lastName = "Bernheim"
//    println(p.firstName + " " + p.lastName)

    // 2. val makes fields read-only
//    class Person1(val firstName : String, val lastName : String)
//    val p1 = new Person1("Bill", "Panner")
//    p1.firstName = "William"  // error

//    3.
    val p2 = new Person2("Kim", "Carnes")
    println(p2.age)
    p2.age = 30
    p2.printFullName()

  }

  class Person2(var firstName: String, var lastName: String) {

    println("the constructor begins")

    // 'public' access by default
    var age = 0

    // some class fields
    private val HOME = System.getProperty("user.home")

    // some methods
    override def toString(): String = s"$firstName $lastName is $age years old"

    def printHome(): Unit = println(s"HOME = $HOME")
    def printFullName(): Unit = println(this)

    printHome()
    printFullName()
    println("you've reached the end of the constructor")

  }
}
